<?php

namespace app\admin\model\consult;

use think\Model;


class Reply extends Model
{

    

    

    // 表名
    protected $name = 'consult_reply';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'sex_text',
        'process_time_text',
        'start_time_text',
        'ent_time_text',
        'type_text'
    ];
    

    
    public function getSexList()
    {
        return ['0' => __('Sex 0'), '1' => __('Sex 1')];
    }

    public function getTypeList()
    {
        return ['0' => __('Type 0'), '1' => __('Type 1'), '2' => __('Type 2')];
    }


    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getProcessTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['process_time']) ? $data['process_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getStartTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getEntTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ent_time']) ? $data['ent_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setProcessTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setStartTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setEntTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('addons\third\model\Third', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function learncateteacher()
    {
        return $this->belongsTo('app\admin\model\LearnCateTeacher', 'teacher_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function consultroom()
    {
        return $this->belongsTo('app\admin\model\ConsultRoom', 'consult_room_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
